﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Data;

namespace PDNPAS
{
    class GetDataFromXmlDoc
    {
        static void Main(string[] args)
        {
            GetXmlDocument("电网CIM模型.xml");
        }
        private static void GetXmlDocument(string xmlFileName)
        {
            //获取文档对象
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlFileName);
            //获得文档根节点
            XmlNode xn = xmlDoc.DocumentElement;
            XmlNodeList xnlChildNodes = xn.ChildNodes;
            DataTable dtSubstation = new DataTable("Substation");
            string deviceType = "";
            foreach (XmlNode xnChildNode in xnlChildNodes)
            {
                XmlElement xeChild = xnChildNode as XmlElement;
                deviceType = xeChild.LocalName.ToLower();
                if (deviceType.Equals("substation"))
                {
                    procSubStation(xeChild, dtSubstation);
                    continue;
                }
            }
        }

        static void procSubStation(XmlElement xe, DataTable dt)
        {
            string id = "", name = "", desc = "", aliasName = "";
            id = xe.GetAttribute("rdf:ID");
            XmlNodeList xnlChildNodes = xe.ChildNodes;
            foreach (XmlNode xnChild in xnlChildNodes)
            {
                if (xnChild.LocalName.ToLower().Equals("identifiedobject.name"))
                    name = xnChild.InnerText;
                if (xnChild.LocalName.ToLower().Equals("identifiedobject.description"))
                    desc = xnChild.InnerText;
                if (xnChild.LocalName.ToLower().Equals("identifiedobject.aliasname"))
                    aliasName = xnChild.InnerText;

                DataRow dr = dt.NewRow();
                dr["id"] = id;
                dr["name"] = name;
                dr["aliasName"] = aliasName;
                dt.Rows.Add(dr);
            }
        }
    }
}
